package org.tang.springcloudvv.cxf.controller;

import org.springframework.web.bind.annotation.*;
import org.tang.springcloudvv.cxf.client.UserInfoWSServiceImpl;
import org.tang.springcloudvv.cxf.client.UserInfoWSServiceImplService;

import javax.xml.namespace.QName;
import java.net.URL;

@RestController
public class UserInfoClientController {

    private static final QName SERVICE_NAME = new QName("http://impl.service.cxf.springcloudvv.tang.org/", "UserInfoWSServiceImplService");

    /**
     * description: 获取用户信息
     */
    @RequestMapping("/client/getUserInfo")
    public String getUserInfo() throws Exception {

        URL wsdlURL = UserInfoWSServiceImplService.WSDL_LOCATION;

        UserInfoWSServiceImplService ss = new UserInfoWSServiceImplService(wsdlURL, SERVICE_NAME);
        UserInfoWSServiceImpl port = ss.getUserInfoWSServiceImplPort();
        String _getInfo__return = port.getInfo();

        return _getInfo__return;
    }

    @PostMapping("/client/getUser")
    public org.tang.springcloudvv.cxf.client.User getUser(org.tang.springcloudvv.cxf.client.User user) throws Exception {

        URL wsdlURL = UserInfoWSServiceImplService.WSDL_LOCATION;

        UserInfoWSServiceImplService ss = new UserInfoWSServiceImplService(wsdlURL, SERVICE_NAME);
        UserInfoWSServiceImpl port = ss.getUserInfoWSServiceImplPort();
        user.setUserId(""+System.currentTimeMillis());
        return port.getUser(user);

    }
    @PostMapping("/client/addUser")
    public org.tang.springcloudvv.cxf.client.User addUser(org.tang.springcloudvv.cxf.client.User user) throws Exception {

        URL wsdlURL = UserInfoWSServiceImplService.WSDL_LOCATION;

        UserInfoWSServiceImplService ss = new UserInfoWSServiceImplService(wsdlURL, SERVICE_NAME);
        UserInfoWSServiceImpl port = ss.getUserInfoWSServiceImplPort();
        user.setUserId(""+System.currentTimeMillis());
        return port.addUser(user);

    }


    /**
     * description: 获取用户json作为前面方法的入参
     */
    @RequestMapping(value = "/client/getUserJson" ,method = RequestMethod.POST)
    public org.tang.springcloudvv.cxf.client.User getUser(@RequestParam("id") String id) throws Exception {

        org.tang.springcloudvv.cxf.client.User user = new org.tang.springcloudvv.cxf.client.User();
        user.setUserId(id);
        user.setUserName("testUsername");
        user.setAge(18);
        user.setPhone(""+System.currentTimeMillis());
        return user;
    }

}
